package domain

// User
// json 序列化与反序列化名称，omitempty如果为空，则从JSON中忽略,json:"-"忽略该字段(不会出现在JSON中)
// gorm：column 数据库对应字段
// form 用于HTML表单数据和URL查询参数
// binding 用于请求参数验证的标签
type User struct {
	Id     uint   `json:"id" form:"id" gorm:"column:id" binding:""`
	Name   string `json:"name" form:"name" gorm:"column:user_name" binding:"required,min=12,max=50"`
	Age    string `json:"age" form:"age" gorm:"column:age" binding:"required,gte=0,lte=150"`
	Mobile string `json:"mobile,omitempty" form:"mobile" gorm:"column:phone" binding:"required,phone"`
	Email  string `json:"email,omitempty" form:"email" gorm:"column:email" binding:"required,email"`
}

// TableName 通过函数指定表名,固定函数名:TableName
func (User) TableName() string {
	return "user"
}

func (u User) getName(perm string) string {
	if perm == "all" {
		return u.Name
	}
	return ""
}

func (u User) mobile(needStar bool) string {
	if needStar {
		return u.Mobile
	}
	return u.Mobile
}
